﻿using lDAL;

namespace DAL
{
    public class UserDAL<T>: lUserDAL<T> where T : class
    {
        private readonly MyDbContext db;

        public UserDAL(MyDbContext db)
        {
            this.db = db;
        }

        public async Task<int> AddAsync(T t)
        {
            await db.Set<T>().AddAsync(t);
            return await db.SaveChangesAsync();
        }

        public async Task<int> AddRangeAsync(List<T> list)
        {
            await db.Set<T>().AddRangeAsync(list);
            return await db.SaveChangesAsync();
        }

        public async Task<int> DeleteAsync(T t)
        {
            db.Set<T>().Remove(t);
            return await db.SaveChangesAsync();
        }

        public async Task<int> DeleteRangeAsync(List<T> list)
        {
            db.Set<T>().RemoveRange(list);
            return await db.SaveChangesAsync();
        }

        public IQueryable<T> GetAllAsync()
        {
            return db.Set<T>();
        }

        public async Task<int> UpdateAsync(T t)
        {
            db.Set<T>().Update(t);
            return await db.SaveChangesAsync();
        }

        public async Task<int> UpdateRangeAsync(List<T> list)
        {
            db.Set<T>().UpdateRange(list);
            return await db.SaveChangesAsync();
        }
    }
}
